import * as types from '../mutation-types'

const state = {
  alertShow: false,
  alertOptions: {}
}

const getters = {
  alertShow: state => state.alertShow,
  alertOptions: state => state.alertOptions
}

const actions = {
  showAlert({commit}, {style, content, closable, timer}) {
    commit(types.SET_ALERT_SHOW, true)
    commit(types.SET_ALERT_OPTIONS, {
      style: style || 'success',
      content: content || '未知提示',
      closable: closable || true,
      timer: timer || 3000
    })
  },
  closeAlert({commit}) {
    commit(types.SET_ALERT_SHOW, false)
    commit(types.SET_ALERT_OPTIONS, {})
  }
}

const mutations = {
  [types.SET_ALERT_SHOW](state, flag) {
    state.alertShow = flag
  },
  [types.SET_ALERT_OPTIONS](state, options) {
    state.alertOptions = options
  }
}

export default {
  state,
  getters,
  mutations,
  actions
}
